#include <stdio.h>
#include <getch.h>

#include "tchManage.h"
#include "tchFunc.h"
#include "tools.h"

void tchManage(int account)
{
	for(;;)
	{
		tchView();
		switch(getch())
		{
			case '1': //添加学生
				tchAddStuView(); 
				break;
			case '2': //删除学生
			{
				int id = 0;
				int idConfirm = 0;
				printf("请输入要删除的学生学号:\n");
				scanf("%d",&id);
				while(id > 2000 || id < 1001 || 0 == student[id-1001].id || 2 == student[id-1001].flag)
				{
					printf("学号不合法！请重新输入:\n");
					scanf("%d",&id);
				}
				printf("请再次输入要删除的学生学号:\n");
				scanf("%d",&idConfirm);
				if(id == idConfirm)
				{
					tchDeleteStu(id);
				}
				else
				{
					printf("两次学号不一致，请重试！\n");
					anykey_continue();
				}
			}	break;
			case '3': //修改学生
				tchModifyStuView(); break;
			case '4': //查询学生
				tchSearchStuView(); break;
			case '5': //添加成绩
				tchAddScoreView(); break;
			case '6': //重置学生密码
			{
				int id = 0;
				char choice = 0;
				printf("请输入需要重置的学生学号:\n");
				scanf("%d", &id);
				getchar();
				while(1001 > id || 2000 < id || 0 == student[id-1001].id)
				{
					printf("学号不合法！请重新输入:\n");
					scanf("%d",&id);
					getchar();
				}
				printf("学号\t姓名\t\t性别\n");
				printf("%d\t%-12s\t%s\n",student[id-1001].id,student[id-1001].name,student[id-1001].sex=='w'?"女":"男");
				printf("确认重置该学生？(y/n)\n");
				for(;;)
				{
					scanf("%c",&choice);
					getchar();
					if('y' == choice)
					{
						tchResetStuPassword(id);
						printf("重置成功！\n");
						break;
					}
					else if('n' == choice)
					{
						break;
					}
					else
					{
						 printf("请确认(y/n)\n");
					}
				}
				anykey_continue();
			}	break;
			case '7': //显示在校学生
				tchViewStuInfo(); break;
			case '8': //显示离校学生
				tchViewLeaveStuInfo(); break;
			case '9': //退出登陆
				logout(2);break;
		}
	}
}

